from vtkmodules.vtkCommonTransforms import vtkTransform

# define basic structures by implement vtk objects...
class Node(vtkTransform):
    def __init__(self) -> None:
        super().__init__()
        self.name = "Node"
        self.children = []
        self.meshes   = []
        self.parent   = None
        self.skin     = None
        self.visible  = True
        self.extras   = {}

        self.translate  = vtkTransform()
        self.rotate     = vtkTransform()
        self.scale      = vtkTransform()

        # local transform
        self.transform = vtkTransform()
        self.transform.Concatenate(self.translate)
        self.transform.Concatenate(self.rotate)
        self.transform.Concatenate(self.scale)
        
        # self.worldTransform = vtkTransform()
        # self.worldTransform.SetInput(self.transform)
        self.SetInput(self.transform)

    # add a child node
    def AddChild(self, child):
        child.parent = self 
        self.children.append(child)

        # concate transform
        #node.worldTransform.PostMultiply()
        #node.worldTransform.Concatenate(self.worldTransform)
        child.PostMultiply()
        child.Concatenate(self)

    # add a mesh
    def AddMesh(self, mesh):
        self.meshes.append(mesh)
        #self.AddPart(mesh)     

    # trace to the root node...
    def GetRoot(self):
        if self.parent == None:
            return self
        return self.parent.GetRoot()  
    
    def SetVisible(self, v):
        self.visible = v
        self.Modified()

    def __str__(self):
        return f"Node({self.name})"    
    def __repr__(self):
        return f"Node({self.name})"